package com.ebei.admin.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ebei.admin.common.util.ConvertUtil;
import com.ebei.admin.mapper.SysProjectMapper;
import com.ebei.admin.model.entity.SysProject;
import com.ebei.admin.service.SysProjectService;
import com.ebei.common.constant.CommonConstant;
import com.ebei.common.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

@Service
public class SysProjectServiceImpl extends ServiceImpl<SysProjectMapper, SysProject> implements SysProjectService {

    @Autowired
    private SysProjectMapper sysProjectMapper;

    @Override
    public Result delete(Integer id) {
        SysProject sysProject = sysProjectMapper.selectById(id);
        sysProject.setDelFlag(CommonConstant.STATUS_DEL);
        sysProjectMapper.updateById(sysProject);
        return Result.OK;
    }

    @Override
    public Result<Boolean> update(Map<String, Object> map) throws Exception {
        SysProject sysProject = (SysProject) ConvertUtil.mapToObject(map, SysProject.class);
        sysProject.setUpdateTime(new Date());
        sysProjectMapper.updateById(sysProject);
        return Result.OK;
    }

    @Override
    public Result findByOrgId(Integer orgId) {
        return new Result(sysProjectMapper.findByOrgId(orgId), Result.SUCCESS);
    }
}
